package corewarsxxi.logic;

import corewarsxxi.logic.throwables.processHalt;
import corewarsxxi.logic.throwables.warriorHasNoProcesses;
import java.io.Serializable;
import java.util.LinkedList;

/**
 *
 * @author ei10139
 */
public class ProcessQueue extends LinkedList<Process> implements Serializable
{

    /**
     * Calls the <i>cycle</i> function of the current process and sets the process to last.
     * @see corewarsxxi.logic.Process#cycle()
     * @throws warriorHasNoProcesses
     */
    public void cycle() throws warriorHasNoProcesses
    {
        Process p = this.peek();
        if(p == null)
            throw new warriorHasNoProcesses();
        try
        {
            p.cycle();
            this.add(this.remove());
        } catch(processHalt ph)
        {
            this.remove();
        }
    }

}
